<?php

namespace App\Jobs\Message\Notice;

use Exception;
use App\Jobs\Job;
use App\Tools\Common;

class RobotNewsJob extends Job
{

    protected $data;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // app('log')->info('机器人任务执行');

        $webhook = env('WX_WORK_PATH');

        // 发送机器人消息内容
        Common::request($webhook, [
            // "msg_type" => "text",
            // "content" => $this->data,
            "msgtype" =>  "markdown",
            "markdown" => [
                "content" => $this->data['text']
            ]
        ]);
    }

    /**
     * 任务失败的处理过程
     *
     * @param  Exception  $exception
     * @return void
     */
    public function failed(Exception $exception)
    {
        // 发送任务失败的通知，等等……
        app('log')->info('机器人任务失败---');
        app('log')->info($exception);
    }
}
